<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.DriverManager"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>查询成语数据库</title>
<style type="text/css">
h1{ color:red;}
</style>
</head>
<body>
<h1>成语数据库的前10条记录</h1><% 
//(1)加载驱动
Class.forName("com.mysql.cj.jdbc.Driver");
//(2)建立连接
Connection cn=DriverManager.getConnection("jdbc:mysql://localhost:3306/db", "root", "12qwas");
//(3)创建语句对象
Statement stat=cn.createStatement();
//(4)执行查询获取结果集
ResultSet rs=stat.executeQuery("select cy from chengyu limit 10");
//(5)循环显示每一条记录
while(rs.next()){ //有记录就循环处理
	String cy=rs.getString(1); //获取成语字段的值，列的索引号从1开始
	out.println("<p>"+cy+"</p>");
}
//(6)关闭资源
rs.close();
stat.close();
cn.close();
%>
</body>
</html>